package JDBC;

import java.sql.*;


public class Test {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            connection.setAutoCommit(false);
            String sql="UPDATE teacher " +
                    "SET salary =salary-500 " +

                    "WHERE subject_id=(SELECT id FROM subject WHERE name='语文') ";

        Statement ps = connection.createStatement();
                    int num = ps.executeUpdate(sql);
                    System.out.println(num>0?"修改成功":"修改失败");

//                    connection.rollback();
//                    System.out.println("事务回滚了");

                        connection.commit();
            System.out.println("事务提交了");














        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }}